package com.boco.blch.analysiser.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;

import org.apache.log4j.Logger;
import org.springframework.util.StringUtils;

public class VersionCheckUtil {
	private static Properties pro = new Properties();
	private final static String PATH = "analysiser/latest_version.properties";
	private static Logger logger = Logger.getLogger(VersionCheckUtil.class);
	static{
		init();
	}
	
	private static void init(){
		InputStream in = VersionCheckUtil.class.getClassLoader().getResourceAsStream(PATH);
		try {
			pro.load(in);
		} catch (IOException e) {
			logger.error(e + " 读取版本配置文件时发生错误，请确认文件是否存在！");
		}
	}
	
	private static String getKey(String name){
		return name.toLowerCase();
	}
	
	/**
	 * 判断组件版本是否为最新
	 * @param name 组件名称 (hdfs、hive、flume、hbase、kafka、mapreduce、yarn、spark、zookeeper)
	 * @param version 版本号(如1.0.0)
	 * @return
	 */
	public static boolean isLatestVersion(String name, String version){
//		return version.equals(pro.getProperty(getKey(name)));
		return version.contains(pro.getProperty(getKey(name)));
	}
	
	/**
	 * 获取组件最新版本号
	 * @param name 组件名称 (hdfs、hive、flume、hbase、kafka、mapreduce、yarn、spark、zookeeper)
	 * @return
	 */
	public static String getLatestVersion(String name){
//		return version.equals(pro.getProperty(getKey(name)));
		return pro.getProperty(getKey(name));
	}
	
	
	

}
